package display;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;
import java.util.HashMap;

import service.ArticuloManager;
import domain.Articulo;

public class ArticuloAgregar implements Controller {
 protected final Log logger = LogFactory.getLog(getClass());
 private ArticuloManager ArticuloManager;
 public ModelAndView handleRequest(HttpServletRequest request,
   HttpServletResponse response)
   throws ServletException, IOException {
   
   Articulo prof = new Articulo();
   prof.setId(request.getParameter("id"));
   prof.setNombre(request.getParameter("nombre"));
   prof.setPais(request.getParameter("pais"));
   prof.setAnno(request.getParameter("anno"));
   prof.setCategoria(request.getParameter("categoria"));
   prof.setSubCategoria(request.getParameter("subCategoria"));
   ArticuloManager.addArticulo(prof);
   String now = (new java.util.Date()).toString();
   logger.info("returning articulo view with " + now);
   Map<String, Object> myModel = new HashMap<String, Object>();
   myModel.put("now", now);
   myModel.put("articulos", this.ArticuloManager.getArticulos());
   return new ModelAndView("articuloView", "model", myModel);
 }
 public void setArticuloManager(ArticuloManager ArticuloManager) {
   this.ArticuloManager = ArticuloManager;
} }